package com.ruoyi.ai.controller;

import com.ruoyi.ai.service.impl.LangchainServiceImpl;
import com.ruoyi.common.core.domain.AjaxResult;
import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.model.ollama.OllamaChatModel;
import dev.langchain4j.model.ollama.OllamaEmbeddingModel;
import dev.langchain4j.service.AiServices;
import dev.langchain4j.service.SystemMessage;
import org.springframework.ai.chat.ChatResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

import java.time.Duration;

@RestController
@RequestMapping("/langchain")
public class LangchainController {

    @Autowired
    private LangchainServiceImpl langchainService;


    /**
     * 普通消息
     */
    @GetMapping("/ollamaChatModel")
    public AjaxResult ollamaChatModel(@RequestParam("msg") String msg){
        String answer = langchainService.ollamaChatModel(msg);
        return AjaxResult.success(answer);
    }

    /**
     * 流式消息
     */
    @GetMapping(value = "/ollamaChatStreaming",produces = "text/event-stream")
    public Flux<String> ollamaChatStreaming(@RequestParam("msg") String msg){
        return langchainService.ollamaChatStreaming(msg);
    }

    /**
     * 放行流式消息
     */
    @GetMapping(value = "/ollamaChatStreamingRelease",produces = "text/event-stream")
    public Flux<String> ollamaChatStreamingRelease(@RequestParam("msg") String msg){
        return langchainService.ollamaChatStreaming(msg);
    }
}
